﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAL;
using DTO;
using Utility;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class Admin_SuaLoaiSanPham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (int.Parse(Session["MaPhanQuyen"].ToString()) == 0 || int.Parse(Session["MaPhanQuyen"].ToString()) == 1)
        {

        }
        else
        {
            Response.Redirect("DanhSachLoaiSanPham.aspx");
        }
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
            if (Request.QueryString["id"] == null)
                Response.Redirect("DanhSachLoaiSanPham.aspx");
            int maloai = int.Parse(Request.QueryString["id"]);
            Loai loaisanpham = LoaiBUS.GetById(maloai);

            if (loaisanpham != null)
            {
                txt_maloaisp.Text = loaisanpham.MaLoai.ToString();

                txt_tenloaisanpham.Text = loaisanpham.TenLoai;
               
            }
            else
            {
                Response.Redirect("DanhSachLoaiSanPham.aspx");
            }
    }

    protected void bt_sua_Click(object sender, EventArgs e)
    {
        if (txt_tenloaisanpham.Text != "")
        {
            Loai loaisanpham = new Loai();

            loaisanpham.MaLoai = int.Parse(txt_maloaisp.Text);
            loaisanpham.TenLoai = txt_tenloaisanpham.Text;
            
            LoaiBUS.UPDATE(loaisanpham);
            Response.Redirect("DanhSachLoaiSanPham.aspx");
        }
        else
        {
            lb_msg.Text = "Bạn phải điền đầy đủ thông tin";
        }
    }
}